using System.Buffers;
using SuperSocket.ProtoBase;

namespace SuperSocketProxy;

public sealed class ProxySwitchPipeFilter : PipelineFilterBase<SocketProxyPacket>
{
    public override SocketProxyPacket Filter(ref SequenceReader<byte> reader)
    {
        reader.TryPeek(out var proxyType);//尝试弹出一个字节判断下一个过滤器类型
       
        switch (proxyType)
        {
            case 0x43://"C"
                NextFilter = new HttpProxyPipeFilter();
                break;
            case 0x05:
                NextFilter = new Socket5HandshakePipeFilter();
                break;
            case 0x06:
                NextFilter = new Socket6PipeFilter();
                break;
            default:
                throw new ProtocolException($"不支持该代理类型{proxyType}");
        }
        
        return default;
    }
}